//
//  averageTemplate.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/20.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef averageTemplate_hpp
#define averageTemplate_hpp

#include <stdio.h>
#include <iostream>


class Cent3 {
    
private:
    int m_cents;
    
public:
    
    Cent3(int cent):m_cents(cent){
        
    }
    
    friend std::ostream &operator<<(std::ostream &out,Cent3 &c){
        
        out << c.m_cents <<"\n";
        
        return out;
    }
    
    Cent3 &operator+=(Cent3 &c){
        m_cents += c.m_cents;
        return *this;
    }
    
    Cent3 &operator/=(int length){
        m_cents /= length;
        return *this;
    }
    
};

template <class T>

T average(T *cptr,int length){
    
    T sum = 0;
    for (int i = 0; i < length; ++i) {
        sum += cptr[i];
    }
    
    sum /= length;
    return sum;
}

/*
 Cent3 arr[] = {Cent3(1),Cent3(2),Cent3(3)};
 Cent3 c = average(arr, 3);
 std::cout << c;
 */


#endif /* averageTemplate_hpp */
